package com.corpgovernment.organization.dataloader.db;

import com.corpgovernment.organization.entity.db.MbOrgEmployeeInfo;
import com.corpgovernment.organization.entity.db.MbOrgNonEmployeeInfo;
import com.corpgovernment.organization.mapper.MbOrgNonEmployeeMapper;
import com.ctrip.corp.obt.generic.utils.CollectionUtils;
import com.ctrip.corp.obt.generic.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @author jhxue
 * @create 2022-03-01-14:32
 */
@Component
public class MbOrgNonEmployeeLoader {


	@Autowired
	private MbOrgNonEmployeeMapper mbOrgNonEmployeeMapper;

	public List<MbOrgNonEmployeeInfo> selectByIds(List<Long> ids) {
		if (CollectionUtils.isEmpty(ids)){
			return new ArrayList<>();
		}
		Example example = new Example(MbOrgNonEmployeeInfo.class);
		example.createCriteria().andIn("id", ids);
		return mbOrgNonEmployeeMapper.selectByExample(example);
	}

	public boolean findRepeatName(String fullName){
		MbOrgNonEmployeeInfo record = new MbOrgNonEmployeeInfo();
		record.setName(fullName);
		List<MbOrgNonEmployeeInfo> orgEmployeeInfos = mbOrgNonEmployeeMapper.select(record);
		return orgEmployeeInfos.size() > 0;
	}

	public boolean updateById(MbOrgNonEmployeeInfo record) {
		if (record == null || Objects.isNull(record.getId())) {
			return false;
		}
		Example example = new Example(MbOrgNonEmployeeInfo.class);
		example.createCriteria()
				.andEqualTo("id", record.getId());
		return mbOrgNonEmployeeMapper.updateByExampleSelective(record, example) > 0;
	}
}
